require('module-alias/register')
const chalk = require('chalk')
const config = require('config')
const express = require('express')
const bodyParser = require('body-parser')
const session = require('express-session')
const cookieParser = require('cookie-parser')
const routerInstall = require('@/routes')
const requestIp = require('request-ip')
const swaggerInstall = require('@/utils/swagger.util')

async function installapp () {
  const app = express()
  swaggerInstall(app)
  app.use(cookieParser())
  app.use(requestIp.mw())
  app.use(bodyParser.json({ limit: '10mb' }))
  app.use(bodyParser.urlencoded({ limit: '10mb', extended: true }))
  app.use(session(config.get('session')))
  routerInstall(app)
  app.listen(config.get('server.port'), () => {
    console.log('app listening on server ' + chalk.green(`http://${config.get('server.host')}:${config.get('server.port')}`))
  })
}
installapp()
